package com.example.vv.model.accountItem.base.presenter;

import com.example.vv.fragmentWork.entity.WxarticleEntity;
import com.example.vv.fragmentWork.mvp.MvpPresenter;
import com.example.vv.fragmentWork.utlis.LogUtils;
import com.example.vv.model.accountItem.base.contract.AccountItemContract;
import com.example.vv.model.accountItem.base.model.AccountItemModel;
import com.example.vv.res.net.BaseResponse;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

public class AccountItemPresenter extends MvpPresenter<AccountItemContract.View, AccountItemContract.Model> implements AccountItemContract.Presenter{
    @Override
    public void attach(AccountItemContract.View view) {
        super.attach(view);
        model = new AccountItemModel();
    }



    @Override
    public void setWXList(String api) {
        model.GET_WX(api)
                .map(new Function<BaseResponse, WxarticleEntity>() {
                    @Override
                    public WxarticleEntity apply(BaseResponse baseResponse) throws Exception {
                        return new Gson().fromJson(baseResponse.getData(),WxarticleEntity.class);
                    }
                })
                .subscribe(new Consumer<WxarticleEntity>() {
                    @Override
                    public void accept(WxarticleEntity wxarticleEntities) throws Exception {
                        view().getWXList(wxarticleEntities);

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                });
    }
}
